/*******************************************************************************
 * Copyright (c) 2007 University of Oslo.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     University of Oslo - initial API and implementation
 *******************************************************************************/

package com.cea.papyrus.diagram.sequence.sedi.editor;

import org.eclipse.jface.resource.ImageDescriptor;

import com.cea.papyrus.diagraminterchange2.di2.Diagram;

/**
 * Common access point for image resources. The images retured by this class are the basic
 * images for SeDi for Eclipse.
 * 
 * @author frankd@ifi.uio.no
 */
public class ImageLibraryForEclipse extends ImageLibrary {

    /** Maps from logical image name to physical image filename. */
    private static final String[] imageMap =
            new String[] {
                    PALETTE_ICON, "icons/seq.GIF", COMMENT_TOOL, "icons/comment.GIF",
                    INTERACTION_TOOL, "icons/interaction.GIF", LIFELINE_TOOL, "icons/Lifeline.GIF",
                    INTERACTION_USE_TOOL, "icons/iu.GIF", EXECUTION_SPECIFICATION_TOOL,
                    "icons/eo.GIF", DESTRUCTION_EVENT_TOOL, "icons/stop.GIF", STATE_INVARIANT_TOOL,
                    "icons/stateinvariant.GIF", ACTION_TOOL, "icons/action.GIF",
                    COMBINED_FRAGMENT_TOOLBOX, "icons/cf.GIF", COMBINED_FRAGMENT_TOOL,
                    "icons/cf.GIF", SEPARATOR_TOOL, "icons/separator.GIF",
                    INTERACTION_OPERAND_GUARD_TOOL, "icons/guard.GIF", CONTINUATION_TOOL,
                    "icons/continuation.gif", MESSAGES_TOOLBOX, "icons/msgbanner.GIF", SIGNAL_TOOL,
                    "icons/asmessage.GIF", SYNCH_CALL_TOOL, "icons/callmessage.GIF",
                    ASYNCH_CALL_TOOL, "icons/asmessage.GIF", REPLY_TOOL, "icons/replymessage.GIF",
                    CREATE_TOOL, "icons/createmessage.GIF", DESTROY_TOOL,
                    "icons/destroymessage.GIF", NEW_DIAGRAM_WIZARD_BANNER, "icons/sdbanner.gif"
            };

    protected String lookupImagePath(String imageId) {
        for (int i = 0; i < imageMap.length; i += 2)
            if (imageId.equals(imageMap[i]))
                return imageMap[i + 1];
        return null;
    }

    @Override
    public ImageDescriptor getImage(String imageId) {
        if (imageId == null)
            throw new IllegalArgumentException();

        final String relativePath = lookupImagePath(imageId);
        return (relativePath == null) ? null : ImageDescriptor.createFromFile(Diagram.class,
                relativePath);
    }

}
